package com.tanhua.server.controller;

import com.tanhua.domain.db.Settings;
import com.tanhua.server.service.SettingsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
@Slf4j
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     * 接口名称：用户通用设置 - 读取
     * 接口路径：GET/users/settings
     * 需求描述：查询tb_settings通知表，封装SettingsVo返回对象，
     */
    @GetMapping("/settings")
    public ResponseEntity<Object> querySettings(){
        log.info("接口名称：用户资料 - 读取");
        return settingsService.querySettings();
    }

    /**
     * 接口名称：通知设置 - 保存
     * 接口路径：POST/users/notifications/setting
     * 需求描述：添加或者修改通知设置，根据用户id查询设置表如果存在记录执行修改，否者执行添加
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity<Object> saveNotifications(@RequestBody Settings settings){
        log.info("接口名称：通知设置 - 保存");
        return settingsService.saveNotifications(settings);
    }

    /**
     * 接口名称：设置陌生人问题 - 保存
     * 接口路径：POST/users/questions
     * 需求描述：添加或者修改陌生人问题
     */
    @PostMapping("/questions")
    public ResponseEntity<Object> saveQuestions(@RequestBody Map<String,String> paramMap) {
        log.info("接口名称：设置陌生人问题 - 保存");
        return settingsService.saveQuestions(paramMap.get("content"));
    }

    /**
     * 接口名称：黑名单 - 翻页列表
     * 接口路径：GET/users/blacklist
     * 需求描述：查询黑名单用户
     */
    @GetMapping("/blacklist")
    public ResponseEntity<Object> blacklist(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10")Integer pagesize
    ){
        log.info("接口名称：黑名单 - 翻页列表");
        return settingsService.blacklist(page,pagesize);
    }

    /**
     * 接口名称：黑名单 - 移除
     * 接口路径：DELETE/users/blacklist/{userId}
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity<Object> deleteBlackUser(@PathVariable("uid") Long blackUserId){
        log.info("接口名称：黑名单 - 移除");
        return settingsService.deleteBlackUser(blackUserId);
    }
}
